# Data comparison script for old and new datasets
old_data = {
    "app": (37420, 0),
    "channel_in": (524392, 0),
    "dztbdapp": (180365, 1),
    "motor": (882199, 3),
    "rpa": (464947, 12),
    "shoukuan": (439439, 37),
    "uba": (28, 10),
    "video_server": (91814, 42),
    "全异常文件": (654, 62241),
}

new_data = {
    "app": (230287, 6849),
    "channel": (528407, 3),
    "dztbdapp": (246783, 4),
    "motor": (1565783, 30),
    "rpa": (534559, 6),
    "shoukuan": (743546, 89),
    "uba": (3801421, 81),
    "video_server": (3801415, 87),
    "全异常文件": (27686, 106644),
}

def print_data_comparison(data, title):
    print(f"\n{title}")
    print(f"{'Name':<16} {'Normal':>10} {'Abnormal':>10} {'Accuracy Rate':>15}")
    print("-" * 56)
    for name, (normal, abnormal) in data.items():
        total = normal + abnormal
        acc = (abnormal / total) if name == "全异常文件" else (normal / total if total > 0 else 0)
        print(f"{name:<16} {normal:>10} {abnormal:>10} {acc:>12.6%}")

def analyze_changes():
    print("\nAnalysis")
    print("-" * 56)
    for name in old_data:
        new_name = name if name != "channel_in" else "channel"
        old_normal, old_abnormal = old_data[name]
        new_normal, new_abnormal = new_data[new_name]

        old_total = old_normal + old_abnormal
        new_total = new_normal + new_abnormal
        old_acc = (old_abnormal / old_total) if name == "全异常文件" else (old_normal / old_total if old_total > 0 else 0)
        new_acc = (new_abnormal / new_total) if new_name == "全异常文件" else (new_normal / new_total if new_total > 0 else 0)

        normal_change = new_normal - old_normal
        abnormal_change = new_abnormal - old_abnormal
        acc_change = new_acc - old_acc

        print(f"{new_name}:")
        print(f"  正常数量从 {old_normal:,} 变成 {new_normal:,} ({'+' if normal_change >= 0 else ''}{normal_change:,})")
        print(f"  异常数量从 {old_abnormal:,} 变成 {new_abnormal:,} ({'+' if abnormal_change >= 0 else ''}{abnormal_change:,})")
        print(f"  精确度从 {old_acc:.6%} 变成 {new_acc:.6%} ({'+' if acc_change >= 0 else ''}{acc_change:.6%})")

if __name__ == "__main__":
    print_data_comparison(old_data, "之前的数据")
    print_data_comparison(new_data, "去掉统计值后的数据")
    analyze_changes()